﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.WModel
{
    public partial class WOITMList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "WOITMList";
            }
        }
        #region 属性 (查询条件)


        protected string ItemCode
        {
            get
            {
                return GetRequestValue<string>("ItemCode", "");

            }
        }
        protected string CardCode
        {
            get
            {
                return GetRequestValue<string>("CardCode", "");
            }
        }
        protected string AliasName
        {
            get
            {
                return GetRequestValue<string>("AliasName", "");
            }
        }

        protected string MachineType
        {
            get
            {
                return GetRequestValue<string>("MachineType", "");
            }
        }
        protected string U_KW
        {
            get
            {
                return GetRequestValue<string>("U_KW", "");
            }
        }

        protected string U_GW
        {
            get
            {
                return GetRequestValue<string>("U_GW", "");
            }
        }

        protected override string orderField
        {
            get
            {
                return GetRequestValue<string>("orderfield", "u_kw");
            }
        }

        protected override string orderDirection
        {
            get
            {
                return GetRequestValue<string>("orderDirection", "asc");
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }

        protected void DataBind()
        {
            //  string wheresql = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);

            this.rpMenu.DataSource = WOITMController.GetPagination(GetSQLWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataBind();
        }

        protected string GetSQLWhere()
        {
            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(ItemCode))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("ItemCode", QueryOperatorsEnum.包含, ItemCode);
                wheresql = sqlcommonFiled;
            }

            string DOWNSQL = "";
            if (!string.IsNullOrEmpty(AliasName))
            {
                DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("AliasName", QueryOperatorsEnum.等于, AliasName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }

            string MachineTypeSQL = "";
            if (!string.IsNullOrEmpty(MachineType))
            {
                MachineTypeSQL = QueryOperatorsEnumHelper.ConvertCommonOperator(MachineType, QueryOperatorsEnum.大于, "0");
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + MachineTypeSQL;
                }
                else
                {
                    wheresql = MachineTypeSQL;
                }
            }

            string U_KWSQL = "";
            if (!string.IsNullOrEmpty(U_KW))
            {
                U_KWSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("U_KW", QueryOperatorsEnum.包含, U_KW);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + U_KWSQL;
                }
                else
                {
                    wheresql = U_KWSQL;
                }
            }

            string U_GWSQL = "";
            if (!string.IsNullOrEmpty(U_GW))
            {
                U_GWSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("U_GW", QueryOperatorsEnum.包含, U_GW);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + U_GWSQL;
                }
                else
                {
                    wheresql = U_GWSQL;
                }
            }
            return wheresql;
        }
    }
}